﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace XsltDbClient
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();

            txtDomain.Text = Settings.Portal;
            txtUsername.Text = Settings.Login;
        }

        private void Login_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult == DialogResult.OK)
            {
                if (ServiceUtils.CreateClient(txtDomain.Text, txtUsername.Text, txtPassword.Text) == null)
                    e.Cancel = true;
                else
                {
                    Settings.Portal = txtDomain.Text;
                    Settings.Login = txtUsername.Text;
                }
            }
        }

        public string Username { get { return txtUsername.Text; } }
        public string Password { get { return txtPassword.Text; } }

        private void Login_Load(object sender, EventArgs e)
        {
            if ( txtDomain.Text.Length > 0 )
                txtUsername.Select();

            if (txtUsername.Text.Length > 0)
                txtPassword.Select();
        }

    }
}
